#-*- coding:utf-8 -*-

from util import *
import json
import random
import bottle
from my_redis import r
from my_mongo import *

#导入web api定义
from apis import *
 
@app.get('/')
def hello():
    return "SmartParker服务接口!"

@app.route('/testRedis')
def testRedis(): 
    ### 进行各种redis操作，如set、get
    r.set("foo", "bar")
    return "get foo=> %s success!" % r.get("foo")

@app.route('/testMongo')
def testMongo(): 
    (db,con) = getMongo()
    #db["user"].insert({"name":"idiot"})
    #user = db["user"].find()[0]
    closeMongo(con)
    #return "get user: %s!" % user['name']
    return "OK"

#404错误页面
@app.error(404)
def error404(error):
    return '找不到啊:' + error.body
#400错误页面
@app.error(400)
def error400(error):
    return '调用参数有误:' + error.body
	
host = '172.31.23.170' if online else 'localhost' 
bottle.run(host=host, port=80, app=app)